package com.wangkang.educms.service.impl;
import com.wangkang.educms.entity.CrmBanner;
import com.wangkang.educms.mapper.CrmBannerMapper;
import com.wangkang.educms.service.CrmBannerService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;
import java.util.List;


@Service
public class CrmBannerServiceImpl extends ServiceImpl<CrmBannerMapper, CrmBanner> implements CrmBannerService {

    /**
     * 查询所有Banner
     *
     * @return
     */
    @Override
    //@Cacheable(key = "'banner'",value = "selectIndexList")
    @Cacheable(key = "'selectIndexList'",value = "banner")
//    public List<CrmBanner> selectAllBanner() {
//
//        //1.根据id进行降序排列，显示排列之后前两条记录
//        LambdaQueryWrapper<CrmBanner> bannerQuery = new LambdaQueryWrapper<>();
//        bannerQuery.orderByDesc(CrmBanner::getSort);
//        //last方法，拼接sql语句
//        bannerQuery.last("limit 2");
//        return list(null);
//    }
    public List<CrmBanner> selectIndexList() {
        //根据banner表中的sort字段，作为降序条件，通过selectList方法去查询出CrmBanner轮播图对象。
        List<CrmBanner> list = baseMapper.selectList(new QueryWrapper<CrmBanner>().orderByDesc("sort"));
        return list;
    }
}